package com.ecube.maintenance.components.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.ecube.maintenance.R;
import com.ecube.maintenance.biz.apis.impl.CarBrandAction;
import com.ecube.maintenance.pojos.UserInfo;
import com.umeng.analytics.MobclickAgent;

public class SplashActivity extends Activity {
    TextView splash_title;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        splash_title= (TextView) findViewById(R.id.splash_title);
        splash_title.startAnimation(AnimationUtils.
                loadAnimation(getApplicationContext(), R.anim.splash_anim));
        CheckTask checkTask = new CheckTask();
        checkTask.execute((Void) null);
    }
    private class CheckTask extends AsyncTask<Void, Void, Byte> {

        @Override
        protected Byte doInBackground(Void... params) {
            UserInfo userInfo = UserInfo.getInstance();
            if (TextUtils.isEmpty(userInfo.getCarFactory()) ){
                CarBrandAction.getCarBrands(SplashActivity.this);
            } else {
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return 0;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            splash_title.setText("数据加载中...");
        }

        @Override
        protected void onPostExecute(Byte aByte) {
            super.onPostExecute(aByte);
            Intent intent = new Intent(getApplicationContext(), MainActivity.class);
            startActivity(intent);
            finish();
        }
    }
    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }
    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }
}
